package com.macro.mall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.macro.mall.dto.e.ReportKeyEntDTO;
import com.macro.mall.dto.o.ReportKeyOutDTO;
import com.macro.mall.mapper.RpsKeysResultMapper;
import com.macro.mall.model.RpsKeysResult;
import com.macro.mall.service.ReportKeyService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ReportKeyServiceImpl implements ReportKeyService {
    @Autowired
    private RpsKeysResultMapper rpsKeysResultMapper;

    @Override
    public PageInfo<ReportKeyOutDTO> list(ReportKeyEntDTO reportKeyEntDTO) {
        PageHelper.startPage(reportKeyEntDTO.getPage(),reportKeyEntDTO.getPageSize());
        List<RpsKeysResult> list = rpsKeysResultMapper.list(reportKeyEntDTO.getDataType());
        PageInfo<RpsKeysResult> rpsKeysResultPageInfo = new PageInfo<>(list);
        List<ReportKeyOutDTO> list1=new ArrayList<>();
        for (RpsKeysResult rpsKeysResult:list){
            ReportKeyOutDTO reportKeyOutDTO = new ReportKeyOutDTO();
            BeanUtils.copyProperties(rpsKeysResult,reportKeyOutDTO);
            list1.add(reportKeyOutDTO);
        }
        PageInfo<ReportKeyOutDTO> reportKeyOutDTOPageInfo = new PageInfo<>(list1);
        reportKeyOutDTOPageInfo.setTotal(rpsKeysResultPageInfo.getTotal());
        return reportKeyOutDTOPageInfo;
    }

    @Override
    public int modify(ReportKeyEntDTO reportKeyEntDTO) {
        RpsKeysResult rpsKeysResult = new RpsKeysResult();
        BeanUtils.copyProperties(reportKeyEntDTO,rpsKeysResult);
        return rpsKeysResultMapper.updateByPrimaryKeySelective(rpsKeysResult);
    }
}
